package com.wizz.trade.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wizz.trade.auth.dto.SysUserDto;
import com.wizz.trade.auth.dto.page.SysUserPageDto;
import com.wizz.trade.auth.entity.SysUser;
import com.wizz.trade.auth.mapper.SysUserMapper;
import com.wizz.trade.auth.service.SysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wizz.trade.auth.vo.SysMenuVo;
import com.wizz.trade.auth.vo.SysRoleVo;
import com.wizz.trade.auth.vo.SysUserSimpleVo;
import com.wizz.trade.common.ServiceException;
import com.wizz.trade.util.PageUtil;
import com.wizz.trade.common.PageVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author fyftless
 * @since 2023-04-02 04:26:06
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Resource
    private SysUserMapper sysUserMapper;

    @Override
    public void insert(SysUser sysUser) {
        sysUserMapper.insert(sysUser);
    }

    @Override
    public void update(SysUser sysUser) {
        sysUserMapper.updateById(sysUser);
    }

    @Override
    public void delete(Long id) {
        sysUserMapper.logicDelete(id);
    }

    @Override
    public void changeStatus(Long id) {
        sysUserMapper.changeStatus(id);
    }

    @Override
    public PageVo<SysUser> getPage(SysUserPageDto sysUserDto) {
        IPage<SysUser> page = sysUserMapper.getPage(PageUtil.initPage(sysUserDto), sysUserDto);
        return new PageVo<>(page);
    }

    @Override
    public void bindRole(Long userId, List<Long> roles) {
        sysUserMapper.clearRole(userId);
        sysUserMapper.bindRole(userId, roles);
    }

    @Override
    public List<SysUserSimpleVo> getUserSimpleVoList(Long roleId) {
        return sysUserMapper.getUserSimpleVoList(roleId);
    }

    @Override
    public void modifySelfUserInfo(SysUser sysUser) {
        sysUserMapper.modifySelfUserInfo(sysUser.getId(),sysUser.getUserName(),sysUser.getWechat(),sysUser.getEmail(),sysUser.getPhonenumber());

    }

}
